package MyAdmin.Controller;

import MyFramePro.Domain.ResponseResult;
import MyFramePro.Service.Impl.UploadServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
public class UploadController {

    @Resource
    private UploadServiceImpl uploadService;

    @PreAuthorize("@myPer.hasAuthority('upload')") //这里进行传入权限信息
    @PostMapping(value = "/upload")
    public ResponseResult upload(@RequestParam("img")MultipartFile multipartFile){

        try {
            return uploadService.uploadImg(multipartFile);
        } catch (Exception e) {
            throw new RuntimeException("文件上传失败!");
        }

    }

}
